package ihm.panel.info;

import ihm.applet.KrakenApplet;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

import enumTypes.Rank;

public class HelpPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private KrakenApplet applet;
	private JEditorPane help_jtp;
	
	public HelpPanel(KrakenApplet applet) {
		this.applet = applet;
	}
	
	public void initPanel(Rank rank) {
		help_jtp = new JTextPane();
		help_jtp.setEditable(false);
		URL helpURL = null;
		try {
			if(rank.equals(Rank.Administrateur))
				helpURL = new File("C:\\Users\\B182JS\\workspace\\vsm\\help\\help_admin.html").toURI().toURL();
			else
				helpURL = new File("C:\\Users\\B182JS\\workspace\\vsm\\help\\help_user.html").toURI().toURL();
		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		}
		
		if (helpURL != null) {
			try {
				help_jtp.setPage(helpURL);
			} catch (IOException e) {
				e.printStackTrace();
				System.err.println("Attempted to read a bad URL: " + helpURL);
			}
		} else {
			System.err.println("Couldn't find file: user_help.html");
		}

		//Put the editor pane in a scroll pane.
		JScrollPane editorScrollPane = new JScrollPane(help_jtp);
		editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		editorScrollPane.setPreferredSize(this.getParent().getSize());
		add(editorScrollPane);
	}

}
